package com.qf.news.service.impl;

import com.qf.news.entity.NewsComment;
import com.qf.news.mapper.NewsCommentMapper;
import com.qf.news.service.NewsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/8 8:25
 * @Version 1.0
 */
@Service
public class NewsCommentServiceImpl implements NewsCommentService {

    @Autowired
    private NewsCommentMapper newsCommentMapper;
    @Override
    public void insert(NewsComment newsComment) {
        int i = newsCommentMapper.insertSelective(newsComment);
        if(i!=1){
            System.out.println("添加评论失败");
            throw new RuntimeException("添加评论失败");
        }
    }

    @Override
    public void deleteAll(Integer newsid) {
        newsCommentMapper.deleteByNewsId(newsid);
    }

    @Override
    public List<NewsComment> findAllByNewsId(Integer newsid) {
        List<NewsComment> newsCommentList = newsCommentMapper.selectByNewsId(newsid);
        return newsCommentList;
    }

}
